#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>
#define OJ_TEST 0
#define LOCAL_TEST 0

#define M 901

struct char_count{
	int ch, cnt;
};
struct char_count record[26];
int cmp(const void *a, const void *b){
	const struct char_count *aa = (const struct char_count*)a;
	const struct char_count *bb = (const struct char_count*)b;
	return (bb->cnt - aa->cnt)?(bb->cnt-aa->cnt):(aa->ch-bb->ch);
}
static void solve(void){
	int n, ch, idx;
	scanf("%d", &n);
	for(idx=0; idx<26; ++idx){
		record[idx].cnt = 0;
		record[idx].ch = 'A'+idx;
	}
	while((ch=getchar())!=EOF){
		if(isalpha(ch)){
			idx = toupper(ch) - 'A';
			++record[idx].cnt;
		}
	}
	qsort(record, 26, sizeof(record[0]), cmp);
	for(idx=0; idx<26; ++idx){
		if(record[idx].cnt){
			printf("%c %d\n", record[idx].ch, record[idx].cnt);
		}
	}
}
#if OJ_TEST
	int main(int ac, char *av[]){
		solve();
		return 0;
	}
#elif  LOCAL_TEST
	void run(void){
		solve();
	}

#else

#endif
